<?php
/*
 * @FilePath: Order.php
 * @Author: 谭贤伟
 * @Date: 2023-04-08 10:01:28
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-04-09 11:03:51
 * @Descripttion: 
 */

/**
 * 申请订单控制器
 * @author 聂哥
 * @Date: 2023-03-06 10:46:45
 */

namespace app\admin\controller\supply;

use app\common\controller\SupplyController;
use app\admin\model\SupplyOrders;

class Order extends SupplyController
{

    public function index()
    {
        if ($this->request->isAjax()) {
            $select = SupplyOrders::where('type', 1)
                ->page($this->request->param('page'), $this->request->param('limit'))
                ->select();
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $select->count(),
                'data'  => $select,
            ];
            return json($data);
        }
        return $this->fetch();
    }
    public function index2()
    {
        if ($this->request->isAjax()) {
            $select = SupplyOrders::where('type', 2)
                ->page($this->request->param('page'), $this->request->param('limit'))
                ->select();
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $select->count(),
                'data'  => $select,
            ];
            return json($data);
        }
        return $this->fetch();
    }
    public function delete($id)
    {
        if (!$id) {
            $this->error('缺少参数id');
        }

        $user = SupplyOrders::find(intval($id));
        if (!$user) {
            $this->error('删除数据不存在');
        }
        try {
            $user->delete();
        } catch (\Exception $e) {
            $this->error('删除失败',$e->getMessage());
        }
        $this->success('删除成功');
    }
}
